package com.sqltoy.helloworld.service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

import org.junit.jupiter.api.Test;
import org.sagacity.sqltoy.dao.LightDao;
import org.sagacity.sqltoy.model.MapKit;
import org.sagacity.sqltoy.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.alibaba.fastjson2.JSON;
import com.sqltoy.helloworld.dto.OrderInfoVO;
import com.sqltoy.helloworld.entity.OrderInfo;

/**
 * 
 * @author zhongxuchen
 *
 */
@SpringBootTest
public class OrderInfoServiceTest {
	@Autowired
	OrderInfoService orderInfoService;

	@Autowired
	LightDao lightDao;

	@Test
	public void testCreateOrderInfo() {
		OrderInfoVO orderInfoVO = new OrderInfoVO();
		orderInfoVO.setOrderType("PO");
		orderInfoVO.setOrganId("100007");
		orderInfoVO.setProductCode("P0001");
		orderInfoVO.setPrice(BigDecimal.valueOf(100));
		orderInfoVO.setQuantity(BigDecimal.valueOf(100));
		orderInfoVO.setTotalAmt(BigDecimal.valueOf(10000));
		orderInfoVO.setUom("KG");
		orderInfoVO.setStaffCode("S0001");
		orderInfoVO.setStatus(1);
		// 定义SqlToyUnifyFieldsHandler公共字段赋值后，就无需设置
		// orderInfoVO.setCreateBy("S0001");
		// orderInfoVO.setCreateTime(LocalDateTime.now());
		// orderInfoVO.setUpdateBy("S0001");
		// orderInfoVO.setUpdateTime(LocalDateTime.now());
		orderInfoService.createOrderInfo(orderInfoVO);
	}

	@Test
	public void testUpdateOrderInfo() {
		// id以实际数据库存在的为准
		String id = "25020501530419200000001138";
		OrderInfo orderInfo = new OrderInfo(id);
		orderInfo.setPrice(BigDecimal.valueOf(100));
		orderInfo.setQuantity(BigDecimal.valueOf(120));
		orderInfo.setTotalAmt(BigDecimal.valueOf(12000));
		lightDao.update(orderInfo);
	}

	@Test
	public void testSearchOrderInfo() {
		Page pageModel = orderInfoService.searchOrderInfo(new Page(10, 1),
				MapKit.keys("statusAry", "beginTime", "endTime").values(new Integer[] { 1 },
						LocalDateTime.parse("2024-10-17T00:00:01"), null));
		System.err.println(JSON.toJSONString(pageModel));
	}

}
